""" 通过外键查询
各自独立查询
先查员工，再去查相关工资信息
"""
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'p43.settings')
django.setup(set_prefix=False)
# 所有测试代码，都要在上面4行之下

from employee.models import Employee
from employee.serializers2 import EmpSerializer, SalarySerializer

emgr = Employee.objects
emp = emgr.get(pk=10003)
print(emp)
""" <Emp 10003,Parto-Bamford> """
print(emp.salaries.all())
""" <QuerySet [<Salary: Salary object (24)>, <Salary: Salary object (25)>, <Salary: Salary object (26)>, <Salary: Salary object (27)>, <Salary: Salary object (28)>, <Salary: Salary object (29)>, <Salary: Salary object (30)>]>
"""
print(EmpSerializer(emp).data)
""" {'emp_no': 10003, 'birth_date': '1959-12-03', 'first_name': 'Parto', 'last_name': 'Bamford', 'gender': 1, 'hire_date': '1986-08-28', 'email': None, 'content': None, 'created': '2025-09-18T15:41:29.617962+08:00', 'updated': '2025-09-18T15:41:29.863036+08:00'}
"""
print(SalarySerializer(emp.salaries.all(), many=True).data)  #  many =True 表示多个实例
"""
[{'id': 24, 'from_date': '1995-12-03', 'salary': 40006, 'to_date': '1996-12-02', 'emp_no': 10003}, {'id': 25, 'from_date': '1996-12-02', 'salary': 43616, 'to_date': '1997-12-02', 'emp_no': 10003}, {'id': 26, 'from_date': '1997-12-02', 'salary': 43466, 'to_date': '1998-12-02', 'emp_no': 10003}, {'id': 27, 'from_date': '1998-12-02', 'salary': 43636, 'to_date': '1999-12-02', 'emp_no': 10003}, {'id': 28, 'from_date': '1999-12-02', 'salary': 43478, 'to_date': '2000-12-01', 'emp_no': 10003}, {'id': 29, 'from_date': '2000-12-01', 'salary': 43699, 'to_date': '2001-12-01', 'emp_no': 10003}, {'id': 30, 'from_date': '2001-12-01', 'salary': 43311, 'to_date': '9999-01-01', 'emp_no': 10003}]
"""